package algotradingfx.strategies;

import java.util.List;

import algotradingfx.utils.Constants;
import algotradingfx.utils.FXAsset;
import atp.client.trading.strategies.StrategyPull;
import atp.commons.util.Candlestick;
import atp.commons.util.Candlestick.CandlestickTimeframe;
import atp.commons.util.StrategyInfo;

public class SamplePullStrategy extends StrategyPull {

	private static final long serialVersionUID = -4572262326125714312L;

	private static final String FREQUENCY = "1"; // in minutes
	private static final String STRATEGY_NAME = "SamplePullStrategy";
	private int count = 0;

	public SamplePullStrategy(String ssID, String password) {
		super(new StrategyInfo(STRATEGY_NAME), ssID, password);
	}

	@Override
	public void initialise() {
		setRunFrequency(FREQUENCY);
	}

	private void printCandleDetails(Candlestick c) {
		System.out.println(c.getTimestamp() + ": Candle #" + (++count) + ",\tBroker: " + c.getBroker()
		        + ",\tSecurity: " + c.getSecurity().toString() + ",\tSymbol: " + c.getSymbol() + ",\tClose: "
		        + c.getClose() + ",\tOpen: " + c.getOpen() + ",\tHigh: " + c.getHigh() + ",\tLow: " + c.getLow()
		        + ",\tVolume: " + c.getVolume());
	}

	@Override
	public void run() {
		// List<Candlestick> csticks = getCandlesFrom(Constants.EURUSD,
		// Constants.MOCK_BROKER, CandlestickTimeframe.TIMEFRAME_1M,
		// TimeUtils.oneMinuteBeforeNow());

		List<Candlestick> csticks = getCandles(FXAsset.EURUSD.toString(), Constants.MOCK_BROKER,
		        CandlestickTimeframe.TIMEFRAME_1M, 10);
		System.out.println(STRATEGY_NAME + ": Retrieved " + csticks.size() + " candlesticks.");

		for (Candlestick c : csticks) {
			printCandleDetails(c);
		}
	}
}
